
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2023/05/01
// Design Name:
// Module Name: rm_top
// Project Name: wujian100
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// base ahb addr is 0x4001_0000  none offset
//////////////////////////////////////////////////////////////////////////////////

module rm_top
    (
    input                              rai_clk_i,
    input                              rai_rst_n_i,
    input                 [32 - 1 : 0] rai_haddr_i,
    input                 [4  - 1 : 0] rai_hprot_i,                            //hprot[0]为0，代表是来自tee的访问信号，为1，代表是来自ree的访问信号
    input                 [1  - 1 : 0] rai_hsel_i,
    input                 [3  - 1 : 0] rai_hsize_i,
    input                 [2  - 1 : 0] rai_htrans_i,
    input                 [32 - 1 : 0] rai_hwdata_i,
    input                 [1  - 1 : 0] rai_hwrite_i,

    output                [32 - 1 : 0] rai_hrdata_o,
    output                [1  - 1 : 0] rai_hready_o,
    output                [2  - 1 : 0] rai_hresp_o,
    output                [1  - 1 : 0] rai_r2t_intr_o
    );

wire                      [1  - 1 : 0] r2t_clk_w;
wire                      [1  - 1 : 0] r2t_rst_n_w;
wire                      [1  - 1 : 0] en_box;
wire                      [1  - 1 : 0] write_box;
wire                      [12 - 1 : 0] r2t_addr_w;
wire                      [32 - 1 : 0] r2t_wdat_w;
wire                      [1  - 1 : 0] r2t_rdy_w;
wire                      [32 - 1 : 0] r2t_rdat_w;
wire                      [1  - 1 : 0] r2t_intr_w;

localparam ADDR_W                      = 12;                                   //子模块地址信号位宽，与分配地址空间有关
/************************************/
/*例化子模块                         */
/************************************/

rm_ahb_if
u_rm_ahb_if
    (
    .rai_clk_i                         (rai_clk_i                              ),            
    .rai_rst_n_i                       (rai_rst_n_i                            ),              
    .rai_haddr_i                       (rai_haddr_i                            ),              
    .rai_hprot_i                       (rai_hprot_i                            ),              
    .rai_hsel_i                        (rai_hsel_i                             ),             
    .rai_hsize_i                       (rai_hsize_i                            ),              
    .rai_htrans_i                      (rai_htrans_i                           ),               
    .rai_hwdata_i                      (rai_hwdata_i                           ),               
    .rai_hwrite_i                      (rai_hwrite_i                           ),               
    .rai_hrdata_o                      (rai_hrdata_o                           ),               
    .rai_hready_o                      (rai_hready_o                           ),               
    .rai_hresp_o                       (rai_hresp_o                            ),              
    .rai_r2t_intr_o                    (rai_r2t_intr_o                         ),        

    .r2t_clk_w                         (r2t_clk_w                              ),                  
    .r2t_rst_n_w                       (r2t_rst_n_w                            ),                    
    .en_box                            (en_box                                 ),                   
    .write_box                         (write_box                              ),                   
    .r2t_addr_w                        (r2t_addr_w                             ),                   
    .r2t_wdat_w                        (r2t_wdat_w                             ),                   
    .r2t_rdy_w                         (r2t_rdy_w                              ),                  
    .r2t_rdat_w                        (r2t_rdat_w                             ),                   
    .r2t_intr_w                        (r2t_intr_w                             )                   
    );

spram
   #(
	.ADDR_W                            (ADDR_W                                 )
	)
u_rm_ree2tee_box
    (
    .clk_i                             (r2t_clk_w                              ),
	.rst_n_i                           (r2t_rst_n_w                            ),
    .en_i                              (en_box                                 ),
    .write_i                           (write_box                              ),
	.addr_i                            (r2t_addr_w                             ),
	.wdat_i                            (r2t_wdat_w                             ),
    .rdy_o                             (r2t_rdy_w                              ),
	.rdat_o                            (r2t_rdat_w                             ),
	.intr_o                            (r2t_intr_w                             )    //硬件清除中断标志位，持续一个时钟周期
    );

endmodule

